﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.IO;
using System.Runtime.InteropServices.Automation;
using Infragistics.Documents.Excel;
using System.Reflection;

namespace ibba.src.norisk.page
{
    public partial class PageRelatorios : Page
    {
        public PageRelatorios()
        {
            InitializeComponent();

            CarregaComboRelatorios();

            Loaded += new RoutedEventHandler(Page_Loaded);
        }

        private void CarregaComboRelatorios()
        {
            List<Relatorios> list = new List<Relatorios>();
            list.Add(new Relatorios { NomeRelatorio = "Lista de Trinca de Garantias disponíveis", DscControle = "ControlRelTrincaGarantias" });
            list.Add(new Relatorios { NomeRelatorio = "Log de Importação de Parâmetros", DscControle = "ControlRelImportParametros" });
            list.Add(new Relatorios { NomeRelatorio = "Log Parametrização de Garantias por Contrato", DscControle = "ControlRelGarantiasContrato" });
            list.Add(new Relatorios { NomeRelatorio = "Log Parametrização de Produto Modalidade", DscControle = "ControlRelProdutoModalidade" });
            list.Add(new Relatorios { NomeRelatorio = "Log Parametrização de Teto Mitigação", DscControle = "ControlRelLogTetoMitigacao" });
            list.Add(new Relatorios { NomeRelatorio = "Relatório PGR3", DscControle = "ControlRelPGR3" });

            this.cboTipoRelatorio.SelectedValuePath = "NomeRelatorio";
            this.cboTipoRelatorio.ItemsSource = list;
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void cboTipoRelatorio_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cboTipoRelatorio.SelectedItem != null)
                RenderControl(((ibba.src.norisk.page.Relatorios)(cboTipoRelatorio.SelectedItem)).DscControle.ToString());
        }

        void RenderControl(string currentControl)
        {
            Type type = this.GetType();
            Assembly assembly = type.Assembly;
            UserControl newPage = (UserControl)assembly.CreateInstance("ibba.src.norisk.Controls." + currentControl);
            stpContent.Children.Clear();
            stpContent.Children.Add(newPage);
        }

        public void ExibeCarregando(bool enable, string busyContent)
        {
            activity.BusyContent = busyContent;
            activity.IsBusy = enable;
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ibba.src.norisk.Controls.ControlRelGarantiasContrato.ParentPage = this;
            ibba.src.norisk.Controls.ControlRelImportParametros.ParentPage = this;
            ibba.src.norisk.Controls.ControlRelLogTetoMitigacao.ParentPage = this;
            ibba.src.norisk.Controls.ControlRelPGR3.ParentPage = this;
            ibba.src.norisk.Controls.ControlRelProdutoModalidade.ParentPage = this;
            ibba.src.norisk.Controls.ControlRelTrincaGarantias.ParentPage = this;
        }

    }

    public class Relatorios
    {
        public String NomeRelatorio { get; set; }
        public String DscControle { get; set; }
    }
}
